package run.halo.app.model.entity.front;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import run.halo.app.model.entity.BaseEntity;
import run.halo.app.utils.DateUtils;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;

/**
 * c端用户实体类
 */
@Data
@Entity
@Table(name = "customer")
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Customer extends BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    /**
     * uuid
     */
    @Column(name = "uuid", nullable = false)
    private String uuid;

    /**
     * openId
     */
    @Column(name = "open_id", nullable = false)
    private String openId;

    /**
     * User name.
     */
    @Column(name = "username", length = 50, nullable = false)
    private String username;

    /**
     * User nick name,used to display on page.
     */
    @Column(name = "nickname", nullable = false)
    private String nickname;

    /**
     * Password.
     */
    @Column(name = "password")
    private String password;

    /**
     * User email.
     */
    @Column(name = "email", length = 127)
    private String email;

    /**
     * User avatar.
     */
    @Column(name = "avatar", length = 1023)
    private String avatar;

    /**
     * 手机号码
     */
    @Column(name = "phone_number", length = 50)
    private String phoneNumber;

    /**
     * 身份证号码
     */
    @Column(name = "id_card", length = 50)
    private String idCard;

    /**
     * 真实姓名
     */
    @Column(name = "name", length = 20)
    private String name;

    @Column(name = "last_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastTime;

    @Column(name = "last_ip",length = 30)
    private String lastIp;

    @PrePersist
    protected void prePersist() {
        Date now = DateUtils.now();
        if (lastTime == null) {
            lastTime = now;
        }
    }
}
